package com.zang.blogz.controller;


import com.zang.blogz.model.input.ro.MenuRO;
import com.zang.blogz.model.output.UserMenuVO;
import com.zang.blogz.result.Result;


import com.zang.blogz.service.MenuService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 朵橙i
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/blogz/menu")
@Api(tags = "菜单模块")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/admin/getMenuTreeBy")
    @ApiOperation(value = "得到菜单树", tags = "得到菜单树")
    public List<UserMenuVO> getResourceTreeBy() {

        return menuService.getMenuTreeBy();
    }

    @PostMapping("/admin/save")
    @ApiOperation(value = "添加菜单", tags = "添加菜单")
    public Result<MenuRO> save(@RequestBody MenuRO menuRO){

        return menuService.saveMenu(menuRO);
    }

    @PostMapping("/admin/update")
    @ApiOperation(value = "更新菜单信息", tags = "更新菜单信息")
    public Result<MenuRO> update(@RequestBody MenuRO menuRO){

        return menuService.updateMenu(menuRO);
    }

    @DeleteMapping("/admin/delete")
    @ApiOperation(value = "删除菜单", tags = "删除菜单")
    public Result<Boolean> delete(@RequestParam("id") Integer id){

        return menuService.deleteMenu(id);
    }



}
